﻿using Models.Mailbox;
using Newtonsoft.Json;
using SendMessagePage.HomePage;
using SendMessagePage.Util;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Result = Models.Mailbox.Result;

namespace SendMessagePage
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        //查询邮箱配置
        private string GetMailboxConfigUrl = ConfigurationManager.AppSettings["GetMailboxConfig"];

        public static OrderResult<Result> order = new OrderResult<Result>();
        public MainWindow()
        {
            InitializeComponent();
            GetSendExcelConfigure();
        }
       


        private async void Open_Configure(object sender, RoutedEventArgs e)
        {


          //  GetMailboxConfigUrl += PackingUserLogin.User.UserName;

            string result = await AccessWebApiUtil.PostAsyncJson(GetMailboxConfigUrl, "", PackingUserLogin.token);

    

            order = JsonConvert.DeserializeObject<OrderResult<Result>>(result);

            SendExcelConfigure sendExcel = null;
            if (order.result != null && order.result.Count > 0)
            {
                sendExcel = new SendExcelConfigure(order.result[0]);
            }
            else {
                sendExcel = new SendExcelConfigure();
            }
            
            sendExcel.Show();
            this.Close();



        }

   

        private void SendMail_Click(object sender, RoutedEventArgs e)
        {
            SendMail sendMail = new SendMail();
            sendMail.Show();
            this.Close();
        }

        private async void GetSendExcelConfigure() {
            GetMailboxConfigUrl += PackingUserLogin.User.UserName;
            string result = await AccessWebApiUtil.PostAsyncJson(GetMailboxConfigUrl, "", PackingUserLogin.token);

             order = JsonConvert.DeserializeObject<OrderResult<Result>>(result);

        }

        /// <summary>
        /// 定时任务设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Task_Click(object sender, RoutedEventArgs e)
        {
            SetTaskPage setTask = new SetTaskPage();    
            setTask.Show();
            this.Close();

        }

        /// <summary>
        /// 任务配置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TaskConfig_Click(object sender, RoutedEventArgs e)
        {
            TaskConfig task = new TaskConfig();
            task.Show();
            this.Close();

        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

        }
    }
}
